<?php
header('Content-type: application/xls');
header("Content-Disposition:attachment;filename=dts.xls");
$sonam = $dts_xls['NAM'];
if ($dts_xls['TYPE'] == 1) $type ="Tỉnh";
else $type ="Huyện";
?>
	<table>
    <tr>
    	<td colspan="30">Trung tâm bảo vệ thực vật phía Nam</td>
    </tr>
    <tr>
    	<td colspan="30" align="center"><?php echo "SỐ LIỆU BẪY ĐÈN ĐỐI TƯỢNG ".mb_strtoupper($tdoituong['Doituong']['TEN_DT'],'UTF-8')." THÁNG $thangs/$sonam (đơn vị tính: con)";?></td>
    </tr>
    </table>
    <table border="1">
	<tr align="center">
		<td rowspan="2"><strong>TT</strong></th>
		<th width="10%"><strong>Ngày</strong></th>
	<?php
	for ($i=1;$i<= $songay;$i++){
		echo "        <th rowspan=\"2\">$i</th>\n";
		}
	?>
		</tr> 
		<tr align="center">
			<th><strong><?php echo $type ?></strong></th>
		</tr>
	<?php
	$x = 1;
	if ($dts_xls['TYPE'] == 1) {
		foreach ($tinhs as $tinh):
			echo '    <tr class="altrow">';
			echo "    	<td align=\"center\">$x</td>\n";
			echo "    	<td>".$tinh['Tinh']['TEN_T']."</td>\n";
		
	$tinh_id = $tinh['Tinh']['id'];		
	@$data2 = $datas["$tinh_id"];
	if ($data2 <> "") {
			foreach ($data2 as $rows):
			$data[$rows['0']['NGAY']] = $rows['0']['KQ'];
			endforeach;
		}
			
		for ($i=1;$i<= $songay;$i++){
			@$sl =  $data["$i"];
			echo "        <td>".$sl."</td>\n";
			}
		echo "</tr>";
		$x++;
		unset ($data);
		endforeach;
		echo '</table>';
	}
	else if ($dts_xls['TYPE'] == 2) {
		foreach ($huyens as $huyen):
			echo "    <tr>";
			echo "    	<td align=\"center\">$x</td>\n";
			echo "    	<td>".$huyen['Huyen']['TEN_H']."</td>\n";
		
	
	$huyen_id = $huyen['Huyen']['id'];		
	@$data2 = $datas["$huyen_id"];
	if ($data2 <> "") {
			foreach ($data2 as $rows):
			$data[$rows['0']['NGAY']] = $rows['0']['KQ'];
			endforeach;
		}
			
		for ($i=1;$i<= $songay;$i++){
			@$sl =  $data["$i"];
			echo "        <td>".$sl."</td>\n";
			}
		echo "</tr>";
		$x++;
		unset ($data);
		endforeach;
		echo '</table>';
		}
?>
